<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" labelWidth="120" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="xzbjcgdd12"
      :columns="columns"
      :params="fetchParams"
      :dataSource="formDataList"
      :isMemoryPagination="true"
      :onColumnsChange="columns => (this.columns = columns)"
      :isSelectColumn="false"
      :onSyncTableData="tableHandle"
      :isExportExcel="true"
      exportFileName="显示/下载配件采购订单.xlsx"
    >
      <!-- :fetchapi="fetchApi" -->
      <!-- :datakey="'rows'" -->
    </FilterTable>
  </div>
</template>

<script>
/*
 *
 * 显示/下载配件采购订单.
 */

import { authority } from '@/utils/authMixin';
import { downloadOrderInfo } from '@/api/part/report/partPurchaseOrder';
import moment from 'moment';
export default {
  name: 'xzbjcgdd',
  components: {},
  mixins: [authority],
  data() {
    return {
      visible: false,
      topFilterList: this.createTopFilters(),
      fetchApi: downloadOrderInfo,
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true },
      tableData: [], // 表单数据
      formDataList: []
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '采购订单',
          fieldName: 'I_EBELN'
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'I_VIN'
        },
        {
          type: 'RANGE_DATE',
          label: '建立日期',
          style: { minWidth: '120px' },
          initialValue: [
            moment(new Date())
              .subtract(1, 'months')
              .format('YYYY-MM-DD'),
            moment(new Date()).format('YYYY-MM-DD')
          ],
          fieldName: 'I_DATES|I_DATEE'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '三包投诉',
          dataIndex: 'SBTS',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '采购订单号',
          dataIndex: 'EBELN',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '采购订单项号',
          dataIndex: 'EBELP',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },

        {
          title: '配件代码',
          dataIndex: 'MATNR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: '160',
          showOverflowTooltip: true
        },
        {
          title: '采购数量',
          dataIndex: 'MENGE',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '采购价格',
          dataIndex: 'NETPR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '需求单号',
          dataIndex: 'VBELN',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '需求单项号',
          dataIndex: 'POSNR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '经销商代码',
          dataIndex: 'KUNNR',
          align: 'center',

          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '底盘号',
          dataIndex: 'FGSTNR',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '建立日期',
          dataIndex: 'AEDAT',
          align: 'center',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '入库日期',
          dataIndex: 'BUDAT',
          align: 'center',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: 'VGIC反馈',
          dataIndex: 'RESULT',
          align: 'center',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    // 搜索
    changeHandle(val) {
      for (const key in val) {
        if (val[key] == '') {
          val[key] = undefined;
        }
      }
      this.findList(Object.assign({ ImportParameter: val }, val));
      // this.fetchParams = Object.assign({ xhrAbort: false }, { ImportParameter: val }, val);
      // this.columns = [...this.columns];
    },
    async findList(val) {
      let res = await downloadOrderInfo(val);
      this.formDataList = res.data;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    // table动态回调函数
    tableHandle(val) {
      this.tableData = val;
      // console.log(this.tableData);
    },

    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
